<?php
/**
 * Created by PhpStorm.
 * User: 38339
 * Date: 2021-05-21
 * Time: 16:49
 */

namespace app\common\model\auth;
use think\Model;

class CommonAdminActionLog extends Model
{
    protected $name = 'common_admin_action_log';

    // 设置字段信息
    protected $schema = [
        'id'          => 'int', //日志管理
        'admin_name'        => 'string', //操作者
        'ip'      => 'string',    //操作IP
        'create_time' => 'datetime',    //操作时间
        'action'    => 'string', //操作action
        'content'   => 'string', //操作内容
    ];

    /**
     * @param $admin_name 操作者
     * @param $action 操作action
     * @param $contentBefore 变更前数据
     * @param $contentLast 变更后数据
     * @param $type 操作类型[1新增2修改3删除]
     */
    public static function insertLog($admin_name,$action,$content){
        $data = [
            'admin_name' => $admin_name,
            'ip' => get_server_ip(),
            'create_time' => date('Y-m-d H:i:s'),
            'action' => $action,
            'content' => json_encode($content),
        ];
        (new self())->insert($data);
        return true;
    }

    /*
     * 获取列表
     */
    public static function getList($where,$limit_start,$page_size){
        $lists =  self::where($where)->order('id','desc')->limit($limit_start,$page_size)->select();
        return $lists;
    }

    /*
     * 获取总数据条数
     */
    public static function getCount($where){
        return self::where($where)->count();
    }

}